package com.hualan.sfzy.controller.counselor;


import com.hualan.sfzy.entity.counselor.CounselorLeaveword;
import com.hualan.sfzy.service.counselor.CounselorLeavewordService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CounselorLeavewordController {
    @Autowired
    private CounselorLeavewordService counselorLeavewordService;

    @PostMapping("/counselorLeaveword")
    public Result add(@RequestBody CounselorLeaveword counselorLeaveword) {
        int num = counselorLeavewordService.add(counselorLeaveword);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorLeaveword/{id}")
    public Result remove(@PathVariable Integer id) {
        int num = counselorLeavewordService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorLeaveword")
    public Result removeBatch(Integer[] ids) {
        int num = counselorLeavewordService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/counselorLeaveword")
    public Result edit(@RequestBody CounselorLeaveword counselorLeaveword) {
        int num =  counselorLeavewordService.edit(counselorLeaveword);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/counselorLeaveword")
    public Result find(){
        List<CounselorLeaveword> list = counselorLeavewordService.find();
        return Result.success(list);
    }

    @GetMapping("/counselorLeaveword/{id}")
    public Result findById(@PathVariable Integer id) {
        CounselorLeaveword counselorLeaveword = counselorLeavewordService.findById(id);
        return Result.success(counselorLeaveword);
    }

    @GetMapping("/counselorLeaveword/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    CounselorLeaveword counselorLeaveword) {
        Map<String, Object> map = counselorLeavewordService.findByPage(pageNum, pageSize, counselorLeaveword);
        return Result.success(map);
    }
}
